package com.ws.wuse.ui.launch;

import android.Manifest;
import android.os.Build;
import android.util.Log;

import com.ws.base.frame.view.AppDelegate;
import com.ws.base.permissions.PermissionsManager;
import com.ws.base.permissions.PermissionsResultAction;
import com.ws.base.util.LogUtil;
import com.ws.wuse.R;
import com.ws.wuse.app.Constant;

/**
 * User: zhanghang
 * Date: 2016-04-22
 * Time: 14:47
 * FIXME 启动闪屏
 */
public class LaunchDelegate extends AppDelegate {

    @Override
    public int getRootLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void initWidget() {
    }

    /**
     * defaultConfig {
     * minSdkVersion 14
     * targetSdkVersion 19
     * }
     * 临时解决运行时权限
     */
    public void checkPermissions() {

        // android target >= 5.0
        if (Build.VERSION.SDK_INT > 22) {
            requestPermissions();
        }
        // android target < 5.0
        else {
            nextSwitch();
        }
    }

    // 请求获取响应权限
    private void requestPermissions() {
        PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(getActivity(),
                new String[]{
                        Manifest.permission.CAMERA,
                        Manifest.permission.READ_PHONE_STATE,
                        Manifest.permission.RECORD_AUDIO,
                        Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE},
                new PermissionsResultAction() {

                    @Override
                    public void onGranted() {
                        nextSwitch();
                        LogUtil.e(Constant.TAG, "权限请求成功");
                    }

                    @Override
                    public void onDenied(String permission) {
                        LogUtil.e(Constant.TAG, "权限请求失败 : " + permission);
                    }
                });
    }

    // 进入向导页面或者主页面
    private void nextSwitch() {

    }
}